home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / xep / mtile.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  4KB  |  143 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: mtile.c,v 1.2 1997/07/09 13:56:56 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    mtile.c
  35.  *
  36.  *    Mandelbrot tile calculation server.
  37.  *    Receives a request to calculate a tile, generates the tile, and
  38.  *    sends it back.
  39.  *
  40.  *    3 Jun 1991  Robert Manchek  manchek@CS.UTK.EDU.
  41.  *    2 Dec 91  check for null argv[0]
  42.  *    02 Sep 92 - ported to v3
  43.  */
  44.  
  45. #ifdef HASSTDLIB
  46. #include <stdlib.h>
  47. #endif
  48. #include <sys/types.h>
  49. #include <fcntl.h>
  50. #include <stdio.h>
  51. #include "pvm3.h"
  52.  
  53. char* calc_tile();
  54.  
  55.  
  56. main(argc, argv)
  57.     int argc;
  58.     char **argv;
  59. {
  60.     int mytid;                /* my task id */
  61.     int mastertid;            /* who sent us this tile */
  62.     double x1, y1, x2, y2;    /* tile corner coordinates */
  63.     int wd, ht;                /* size of tile */
  64.     char *pix;                /* calculated image */
  65.     int mid;
  66.  
  67.     mytid = pvm_mytid();
  68.  
  69.     /* loop forever reading sizes and coords of tiles we should calculate */
  70.  
  71.     while ((mid = pvm_recv(-1, 1)) > 0) {
  72.         pvm_bufinfo(mid, (int*)0, (int*)0, &mastertid);
  73.         pvm_unpackf("%lf %lf %lf %lf %d %d", &x1, &y1, &x2, &y2, &wd, &ht);
  74.  
  75. /*
  76.         fprintf(stderr, "%dx%d tile between %f,%f and %f,%f\n",
  77.             wd, ht, x1, y1, x2, y2);
  78. */
  79.  
  80.         pix = calc_tile(x1, y1, x2, y2, wd, ht);
  81.  
  82.         pvm_packf("%+ %*c", PvmDataDefault, wd * ht, pix);
  83. /*
  84.         umbuf_dump(pvm_getsbuf(), 1);
  85. */
  86. /*
  87.         pvm_packf("%+ %*c", PvmDataInPlace, wd * ht, pix);
  88. */
  89.  
  90.         if (pvm_send(mastertid, 2)) {
  91.             fprintf(stderr, "error sending image back\n");
  92.         }
  93.  
  94.         free(pix);
  95.     }
  96.     fprintf(stderr, "error receiving work to do\n");
  97.     pvm_exit();
  98.     exit(1);
  99. }
  100.  
  101.  
  102. char*
  103. calc_tile(x1, y1, x2, y2, wd, ht)
  104.     double x1, y1, x2, y2;    /* tile corner coords */
  105.     int wd, ht;                /* size of tile */
  106. {
  107.     char *pix;                        /* calculated image */
  108.     int ix, iy;                        /* pixel coords */
  109.     double x, y;                    /* re, im coords */
  110.     register double ar, ai;            /* accumulator */
  111.     register double a1, a2;
  112.     register int ite;                /* number of iter until divergence */
  113.  
  114.     if (wd < 1 || wd > 2048 || ht < 1 || ht > 2048) {
  115.         fputs("insane wd/ht\n", stderr);
  116.         pvm_exit();
  117.         exit(1);
  118.     }
  119.     pix = (char*)malloc(wd * ht);
  120.     x2 -= x1;
  121.     y2 -= y1;
  122.     for (iy = ht; iy-- > 0; ) {
  123.         y = (iy * y2) / ht + y1;
  124.         for (ix = wd; ix-- > 0; ) {
  125.             x = (ix * x2) / wd + x1;
  126.             ar = x;
  127.             ai = y;
  128.             for (ite = 0; ite < 255; ite++) {
  129.                 a1 = (ar * ar);
  130.                 a2 = (ai * ai);
  131.                 if (a1 + a2 > 4.0)
  132.                     break;
  133.                 ai = 2 * ai * ar + y;
  134.                 ar = a1 - a2 + x;
  135.             }
  136.             pix[iy * wd + ix] = ~ite;
  137.         }
  138.     }
  139.     return pix;
  140. }
  141.  
  142.  
  143.